<template>
	<view class="checklist">
		<view class="nav">
			<u-tabs :list="list1" lineColor="#FF5B1A" :activeStyle="{color: '#FF5B1A'}" @click="change" :scrollable="false"></u-tabs>
		</view>
		<scroll-view scroll-y class="main" @scrolltolower="lower()">
			<view class="list" v-for="(item,index) of list" @click="detail(item)">
				<image v-if="item.user" :src="oss(item.user.avatar)" class="cover" mode=""></image>
				<view class="info">
					<view class="title">
						<view class="l">{{item.user.nickname}}</view>
						<view class="r" v-if="item.status === 0">进行中</view>
						<view class="r" v-else-if="item.status === 1">待审核</view>
						<view class="r" v-else-if="item.status === 2">审核通过</view>
						<view class="r" v-else-if="item.status === -1">审核拒绝</view>
					</view>
					<view class="num">
						<view class="l"><text class="type">提交时间：{{item.submittime | date('yyyy-mm-dd hh:MM')}}</text></view>
					</view>
				</view>
			</view>
			<u-empty v-if="list.length === 0 && finish" mode="data" marginTop="100">
			</u-empty>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list1: [{
					name: '待审核',
					type: 1
				}, {
					name: '进行中',
					type: 0
				}, {
					name: '审核通过',
					type: 2
				}, {
					name: '审核拒绝',
					type: -1
				}, {
					name: '订单取消',
					type: -2
				}],
				page: 1,
				finish: false,
				type: 1,
				list: [],
				show3: false,
				note: '',
				id: ''
			}
		},
		
			mounted() {
				let that = this
				uni.$on('visit', function(data) {
					that.reload()
				})
			},
		onLoad(options) {
			console.log(options)
			this.id = options.id
			this.getList()
		},
		methods: {
			detail(item) {
				// if(item.status === 1) {
				// 	uni.$u.route({
				// 		url: 'pages/my/task/detail',
				// 		params: {
				// 			id: id
				// 		}
				// 	})
				// }
				uni.$u.route({
					url: 'pages/my/task/detail',
					params: {
						id: item.id
					}
				})
			},
			cancel(id) {
				uni.$u.http.post('/checklist', {
					id: id,
					types: 'cancel'
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
						this.reload()
					}
				}).catch((res) => {
						
				})
			},
			tel(mobile) {
				uni.makePhoneCall({
					phoneNumber: mobile
				});
			},
			toast(note) {
				this.note = note
				this.show3 = true
			},
			change(e) {
				console.log(e)
				this.type = e.type
				this.reload()
			},
			reload() {
				this.page = 1
				this.finish = false
				this.list = []
				this.getList()
			},
			lower() {
				this.page++
				this.getList()
			},
			getList() {
				if (this.finish) {
					return
				}
				uni.$u.http.post('/checklist', {
					page: this.page,
					id: this.id,
					type:  this.type,
				}).then(res => {
					if (res.code == 1) {
						this.list = this.list.concat(res.data)
						if (res.data.length === 0) {
							this.finish = true
						}
					}
				}).catch((res) => {
		
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	page{
		height: 100%;
	}
	.checklist{
		height: 100vh;
		position: relative;
		background-color: #F6F6F6;
		.nav{
			display: flex;
			align-items: center;
			justify-content: center;
			flex-shrink: 0;
		}
		
	}
.main{
	position: absolute;
	left: 0;
	width: 100%;
	bottom: 0;
	top: 90rpx;
	padding-top: 20rpx;
	overflow: hidden;
	padding-top: 20rpx;
	.list{
		display: flex;
		margin: 0 20rpx 10rpx;
		padding: 20rpx;
		background-color: #fff;
		border-radius: 10rpx;
		position: relative;
		.cover{
			width: 120rpx;
			height: 120rpx;
			margin-right: 20rpx;
			flex-direction: 0;
			border-radius: 50%;
		}
		.address{
			font-size: 25rpx;
			color: #575859;
			margin: 10rpx 0 20rpx;
		}
		.info{
			flex: 1;
			.title{
				display: flex;
				align-items: center;
				.l{
					flex: 1;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-weight: bold;
				}
				.r{
					color: #428DFC;
					font-size: 24rpx;
					flex-shrink: 0;
					display: flex;
					align-items: center;
				}
			}
			.num{
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 20rpx;
				.l{
					display: flex;
					align-items: center;
					.type{
						color: #999999;
						font-size: 24rpx;
					}
					.word{
						background-color: #FFFAE5;
						height: 36rpx;
						border-radius: 18rpx;
						color: #FF8007;
						font-size: 20rpx;
						padding: 0 20rpx;
						display: flex;
						align-items: center;
					}
				}
				.r{
					color: #FF5B1A;
					font-size: 40rpx;
					.icon{
						font-size: 28rpx;
					}
				}
			}
		}
	}
}
</style>
